//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using System.ComponentModel;
using System.Drawing.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Validation.Configuration.Design.Properties;

namespace EntLibContrib.Validation.Configuration.Design.Nodes
{
	/// <summary>
	/// Externally Configured Object Validator Node
	/// </summary>
	public class ExternallyConfiguredObjectValidatorNode : SingleValidatorNodeBase
	{
		#region Fields
		private string targetRuleSet;
		private string targetConfigurationFile;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the target configuration file.
		/// </summary>
		/// <value>The target configuration file.</value>
		[Required]
		[SRCategory("CategoryGeneral", typeof(Resources))]
		[SRDescription("DescriptionTargetConfigurationFile", typeof(Resources))]
		[Editor(typeof(OpenFileEditor), typeof(UITypeEditor))]
		[FilteredFileNameEditor(typeof(Resources), "ConfigurationFileDialogFilter")]
		[FileValidationAttribute]
		public string TargetConfigurationFile
		{
			get { return targetConfigurationFile; }
			set { targetConfigurationFile = value; }
		}

		/// <summary>
		/// Gets or sets the target rule set.
		/// </summary>
		/// <value>The target rule set.</value>
		[SRCategory("CategoryGeneral", typeof(Resources))]
		[SRDescription("DescriptionTargetRuleSet", typeof(Resources))]
		public string TargetRuleSet
		{
			get { return targetRuleSet; }
			set { targetRuleSet = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="ExternallyConfiguredObjectValidatorNode"/> class.
		/// </summary>
		public ExternallyConfiguredObjectValidatorNode()
			: this(new ExternallyConfiguredObjectValidatorData(Resources.ExternallyConfiguredObjectValidatorNodeName))
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ExternallyConfiguredObjectValidatorNode"/> class.
		/// </summary>
		/// <param name="validatorData">The validator data.</param>
		public ExternallyConfiguredObjectValidatorNode(ExternallyConfiguredObjectValidatorData validatorData)
			: base(validatorData)
		{
			targetRuleSet = validatorData.TargetRuleSet;
			targetConfigurationFile = validatorData.TargetConfigurationFile;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// When overriden in a derived class, this method returns the runtime configuration data represented by this node.
		/// </summary>
		/// <returns>
		/// The runtime configuration data represented by this node, that can de persisted to a configuration file.
		/// </returns>
		public override ValidatorData CreateValidatorData()
		{
			ExternallyConfiguredObjectValidatorData validatorData = new ExternallyConfiguredObjectValidatorData(Name);
			base.SetValidatorBaseProperties(validatorData);

			validatorData.TargetConfigurationFile = targetConfigurationFile;
			validatorData.TargetRuleSet = targetRuleSet;

			return validatorData;
		}
		#endregion
	}
}
